package com.znsd.zl.house.controller;

import com.znsd.zl.house.entity.HouseImage;
import com.znsd.zl.house.entity.RentEntity;
import com.znsd.zl.house.entity.vo.RentRespVO;
import com.znsd.zl.house.service.IRentService;
import com.znsd.zl.utils.BaseController;
import com.znsd.zl.utils.PageUtils;
import com.znsd.zl.utils.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * @ClassName RentController
 * @Description 描述
 * @author zhubin
 * @date 2020-08-21 10:49:33
 * @Version v1.0
 */
@RestController
@RequestMapping("/zl/rent")
public class RentController extends BaseController<IRentService, RentEntity,Integer> {

	@RequestMapping("/list")
	public R list(@RequestParam Map<String,Object> params, RentRespVO house){
		PageUtils pageUtils = service.conditionQueryPage(params,house);
		return R.ok().put("page",pageUtils);
	}

	@RequestMapping("/listAll")
	public R listAll(@RequestParam Map<String,Object> params, RentRespVO house){
		PageUtils pageUtils = service.conditionQueryAll(params,house);
		return R.ok().put("page",pageUtils);
	}

	@RequestMapping("/push")
	public R push(String districtName, Integer page, Integer limit){
		System.out.println("区域信息======"+districtName);
		PageUtils pageUtils = service.push(districtName,page,limit);
		return R.ok().put("page",pageUtils);
	}

	@RequestMapping("/findHouseImage")
	public R findHouseImage(Integer houseId){
		List<String> houseImages = service.findHouseImage(houseId);
		return R.ok().put("page",houseImages);
	}


	@GetMapping("/findHouseProfit")
	public R findHouseProfit(@RequestParam Integer rentId){
		Map map = service.findHouseProfit(rentId);
		return R.ok().put("map",map);
	}

	@GetMapping("/findHouseImages")
	public List<HouseImage> findHouseImages(Integer houseId){
		return service.findHouseImages(houseId);
	}

	@GetMapping("/deleteHouseImage")
	public R deleteHouseImage(Integer imageId){
		System.out.println(imageId);
		this.service.deleteHouseImage(imageId);
		return R.ok("删除房屋图片成功");
	}


	/**
	 * 根据用户Id查询用户的租房信息
	 * @param userId
	 * @return
	 */
	@RequestMapping("findUserHouse")
	public R findUserHouse(Integer userId){
		List<RentEntity> userHouse = service.findUserHouse(userId);
		return  R.ok().put("list",userHouse);
	}

}
